package com.hcy.rabbitruntimeapi.center.handler;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hcy.rabbitbasicmodel.common.MyWebSocketMessage;
import com.hcy.rabbitbasicmodel.enums.Clients;
import com.hcy.rabbitbasicmodel.enums.M_Code;
import com.hcy.rabbitbasicutils.utils.RedisUtils;
import com.hcy.rabbitruntimeapi.center.MessageHandler;
import com.hcy.rabbitruntimeapi.center.MyMessageHandler;
import com.hcy.rabbitruntimeapi.handler.MyWebSocketFrameHandler;
import com.hcy.rabbitruntimeapi.model.dto.WebSocketKey;
import com.hcy.schedulingclient.client.SchedulingLocationClient;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Point;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @Author huchenying
 * @Description
 * @Date 2021/12/15 19:28
 */
@MyMessageHandler(M_Code.CallCustomerLocation)
@Component
public class CallCustomerLocationHandler extends MessageHandler {

    Logger logger = LoggerFactory.getLogger(CallCustomerLocationHandler.class);

    @Autowired
    SchedulingLocationClient schedulingLocationClient;

    @Autowired
    RedisUtils redisUtils;

    @Override
    public void handler(MyWebSocketMessage myWebSocketMessage) {
//        logger.debug("CallCustomerLocationHandler start code -> [{}] , desc -> [{}],orderNumber -> [{}]", myWebSocketMessage.getCode(), myWebSocketMessage.getDesc(),myWebSocketMessage.getData().toString());
        try {
            //验证参数 ， 调用运力系统
            String data = JSON.toJSONString(myWebSocketMessage.getData());
            JSONObject parseObject = JSONObject.parseObject(data);
            String username = myWebSocketMessage.getUsername();
            String log = parseObject.get("log").toString();
            String lat = parseObject.get("lat").toString();
            String point = log+","+lat;
//            logger.info("point = [{}],已缓存",point);
            redisUtils.set("CUSTOMER_GEO_CACHE"+username,point,10, TimeUnit.SECONDS);
        } catch (Exception e) {
            e.getStackTrace();
            logger.error("处理失败！reason -> {}",e.getMessage());
        }
    }
}
